package pluginMain;

import java.util.List;
import java.util.regex.*;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import skill.Skill;

public class WeaponRestrictor {
	public static boolean Stable(Player User, ItemStack item) {
		if (item == null)
			return true;
		if (!item.hasItemMeta())
			return true;

		if (item.getItemMeta().hasLore()) {
			List<String> loreList = item.getItemMeta().getLore();
			if (!loreList.isEmpty()) {
				for (String k : loreList) {
					Pattern p = Pattern.compile("\\[SP\\].*?\\[(.*?)\\].*?\\[(.*?)\\].*?");
					Matcher m = p.matcher(k);
					if (m.find()) {
						String SkillRequest = m.group(1);
						int SkillLevel = Integer.parseInt(m.group(2));
						Skill targetSkill = SP.sm.getPlayerSkills(User).getSkillByName(SkillRequest);

						if (targetSkill == null)
							return false;
						if (targetSkill.getLevel() < SkillLevel) {
							User.sendMessage("使用" + item.getItemMeta().getDisplayName() + "需要"
									+ targetSkill.getSkillBase().getSkillName().toString() + "的等级达到" + SkillLevel + "，目前你的等级为:"
									+ targetSkill.getLevel());
							return false;
						}
					}
				}
				return true;
			} else {
				return true;
			}
		} else {
			return true;
		}
	}
}
